
import importlib
from pathlib import Path
from fastapi import Depends
from fastapi_users.db import SQLAlchemyBaseUserTableUUID, SQLAlchemyUserDatabase
from sqlalchemy.ext.asyncio import AsyncSession

from core.db import Base, engine, get_async_session

# from application import settings
# modules = settings.models_app_register

modules = []
BASE_DIR = Path(__file__).resolve().parent.parent
APPS_DIR = BASE_DIR.joinpath("apps")
filess = APPS_DIR.glob("**/models.py") 
for file in filess:
    modules.append(str(file.resolve()).replace(str(BASE_DIR.resolve()), "")[1:-3].replace("\\", ".").replace("/", "."))

# 导数数据模型的模块
for module in modules:
    module_pag = importlib.import_module(module)


class User(SQLAlchemyBaseUserTableUUID, Base):
    pass

async def create_db_and_tables():
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)


async def get_user_db(session: AsyncSession = Depends(get_async_session)):
    yield SQLAlchemyUserDatabase(session, User)
